package net.jwtools.tmt.domain;

import java.io.Serializable;
import java.util.Iterator;

/**
 * This is an object that contains data related to the TERRITORY table. Do not
 * modify this class because it will be overwritten if the configuration file
 * related to this class is modified.
 * 
 * @hibernate.class table="TERRITORY"
 */

public abstract class BaseTerritory implements Serializable {

	public static String REF = "Territory";
	public static String PROP_TYPE = "type";
	public static String PROP_STATUS = "status";
	public static String PROP_DESCRIPTION = "description";
	public static String PROP_MAP = "map";
	public static String PROP_NUMBER = "number";
	public static String PROP_AREA = "area";
	public static String PROP_ID = "id";
	public static String PROP_INFO = "info";

	// constructors
	public BaseTerritory() {
		initialize();
	}

	/**
	 * Constructor for primary key
	 */
	public BaseTerritory(java.lang.Long id) {
		this.setId(id);
		initialize();
	}

	/**
	 * Constructor for required fields
	 */
	public BaseTerritory(java.lang.Long id, net.jwtools.tmt.domain.Area area,
			java.lang.Integer number) {

		this.setId(id);
		this.setArea(area);
		this.setNumber(number);
		initialize();
	}

	protected void initialize() {
	}

	private int hashCode = Integer.MIN_VALUE;

	// primary key
	private java.lang.Long id;

	// fields
	private java.lang.Integer number;
	private java.lang.String description;
	private java.lang.String info;
	private java.sql.Blob map;
	private net.jwtools.tmt.domain.Status status;
	private net.jwtools.tmt.domain.TerritoryType type;

	// many to one
	private net.jwtools.tmt.domain.Area area;

	// collections
	private java.util.Set<net.jwtools.tmt.domain.IVisit> visits;
	private java.util.Set<net.jwtools.tmt.domain.Territory> surroundingTerritories;
	private java.util.Set<net.jwtools.tmt.domain.AddressGroup> addressGroups;
	/**
	 * Return the unique identifier of this class
	 * 
	 * @hibernate.id generator-class="increment" column="ID"
	 */
	public java.lang.Long getId() {
		return id;
	}

	/**
	 * Set the unique identifier of this class
	 * 
	 * @param id
	 *            the new ID
	 */
	public void setId(java.lang.Long id) {
		this.id = id;
		this.hashCode = Integer.MIN_VALUE;
	}

	/**
	 * Return the value associated with the column: NUMBER
	 */
	public java.lang.Integer getNumber() {
		return number;
	}

	/**
	 * Set the value related to the column: NUMBER
	 * 
	 * @param number
	 *            the NUMBER value
	 */
	public void setNumber(java.lang.Integer number) {
		this.number = number;
	}

	/**
	 * Return the value associated with the column: DESCRIPTION
	 */
	public java.lang.String getDescription() {
		return description;
	}

	/**
	 * Set the value related to the column: DESCRIPTION
	 * 
	 * @param description
	 *            the DESCRIPTION value
	 */
	public void setDescription(java.lang.String description) {
		this.description = description;
	}

	/**
	 * Return the value associated with the column: INFO
	 */
	public java.lang.String getInfo() {
		return info;
	}

	/**
	 * Set the value related to the column: INFO
	 * 
	 * @param info
	 *            the INFO value
	 */
	public void setInfo(java.lang.String info) {
		this.info = info;
	}

	/**
	 * Return the value associated with the column: MAP
	 */
	public java.sql.Blob getMap() {
		return map;
	}

	/**
	 * Set the value related to the column: MAP
	 * 
	 * @param map
	 *            the MAP value
	 */
	public void setMap(java.sql.Blob map) {
		this.map = map;
	}

	/**
	 * Return the value associated with the column: status
	 */
	public net.jwtools.tmt.domain.Status getStatus() {
		return status;
	}

	/**
	 * Set the value related to the column: status
	 * 
	 * @param status
	 *            the status value
	 */
	public void setStatus(net.jwtools.tmt.domain.Status status) {
		this.status = status;
	}

	/**
	 * Return the value associated with the column: type
	 */
	public net.jwtools.tmt.domain.TerritoryType getType() {
		return type;
	}

	/**
	 * Set the value related to the column: status
	 * 
	 * @param status
	 *            the status value
	 */
	public void setType(net.jwtools.tmt.domain.TerritoryType type) {
		this.type = type;
	}

	/**
	 * Return the value associated with the column: AREA_ID
	 */
	public net.jwtools.tmt.domain.Area getArea() {
		return area;
	}

	/**
	 * Set the value related to the column: AREA_ID
	 * 
	 * @param area
	 *            the AREA_ID value
	 */
	public void setArea(net.jwtools.tmt.domain.Area area) {
		this.area = area;
	}

	/**
	 * Return the value associated with the column: visits
	 */
	public java.util.Set<net.jwtools.tmt.domain.IVisit> getVisits() {
		return visits;
	}

	/**
	 * Set the value related to the column: visits
	 * 
	 * @param visits
	 *            the visits value
	 */
	public void setVisits(java.util.Set<net.jwtools.tmt.domain.IVisit> visits) {
		this.visits = visits;
	}

	public void addTovisits(net.jwtools.tmt.domain.IVisit visit) {
		if (null == getVisits())
			setVisits(new java.util.HashSet<net.jwtools.tmt.domain.IVisit>());
		getVisits().add(visit);
	}

	/**
	 * Return the value associated with the column: surroundingTerritories
	 */
	public java.util.Set<net.jwtools.tmt.domain.Territory> getSurroundingTerritories() {
		return surroundingTerritories;
	}

	/**
	 * Set the value related to the column: surroundingTerritories
	 * 
	 * @param surroundingTerritories
	 *            the surroundingTerritories value
	 */
	public void setSurroundingTerritories(
			java.util.Set<net.jwtools.tmt.domain.Territory> surroundingTerritories) {
		this.surroundingTerritories = surroundingTerritories;
	}

	public void addTosurroundingTerritories(
			net.jwtools.tmt.domain.Territory territory) {
		if (null == getSurroundingTerritories())
			setSurroundingTerritories(new java.util.HashSet<net.jwtools.tmt.domain.Territory>());
		getSurroundingTerritories().add(territory);
	}

	public String getSurroundingTerritoriesString() {
		StringBuilder surroundingTer = new StringBuilder();
		if (getSurroundingTerritories()!=null) {

			for (Iterator<Territory> iterator = getSurroundingTerritories()
					.iterator(); iterator.hasNext();) {
				Territory ter = (Territory) iterator.next();
				surroundingTer.append(ter.getNumber());
				surroundingTer.append(" ");
				surroundingTer.append(ter.getDescription());
				surroundingTer.append(", ");
			}
		}
		return surroundingTer.toString();
	}

	public boolean equals(Object obj) {
		if (null == obj)
			return false;
		if (!(obj instanceof net.jwtools.tmt.domain.Territory))
			return false;
		else {
			net.jwtools.tmt.domain.Territory territory = (net.jwtools.tmt.domain.Territory) obj;
			if (null == this.getId() || null == territory.getId())
				return false;
			else
				return (this.getId().equals(territory.getId()));
		}
	}

	public int hashCode() {
		if (Integer.MIN_VALUE == this.hashCode) {
			if (null == this.getId())
				return super.hashCode();
			else {
				String hashStr = this.getClass().getName() + ":"
						+ this.getId().hashCode();
				this.hashCode = hashStr.hashCode();
			}
		}
		return this.hashCode;
	}

	public String toString() {
		return super.toString();
	}

	public java.util.Set<net.jwtools.tmt.domain.AddressGroup> getAddressGroups() {
		return addressGroups;
	}

	public void setAddressGroups(
			java.util.Set<net.jwtools.tmt.domain.AddressGroup> addressGroups) {
		this.addressGroups = addressGroups;
	}

}